<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="menu" content="assetMenu" />
<meta name="nav" content="0" />
<meta name="acc" content="_design" />
<title>设计单位</title>
<!--  通用情况下 不引入 js css  表单验证  js 放置到页面中 -->
<%-- ui tabs --%>
<script type="text/javascript"
	src="<c:url value='/ext/ui/jquery-ui-1.8.12.custom.min.js'/>"></script>
<link href="${ctx}/styles/lightness/jquery-ui-1.8.12.custom.css"
	rel="stylesheet" />
<script type='text/javascript'
	src='${ctx}/scripts/plugin/jquery.autocomplete.js'></script>
	<script type='text/javascript'
	src='${ctx}/scripts/plugin/jquery.liveSearch.js'></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#beginDate").addClass("Wate").bind("click", function(){
   	 WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'});});
	 $("#endDate").addClass("Wate").bind("click", function(){
	 WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'});});
	 $("#orgCode").focus();
	 var id = $("#id").val();
	 if(""==id||null==id){
		 $("#Name").attr("disabled",false);
		 $("#deptName").attr("disabled",false);
	 }
	 
	//单位名称自动补全 -->
	 $("#orgName").liveSearch({url:'${ctx}/project/sign/org/organization!signlist.action?typeId=2' + '&q='});
	 $("#deptName").click(function(){
		    var orgName = $("#orgName").val();
			var orgCode = $("#orgCode").val();
			 $("#dialog-confirm").dialog({
					resizable: false,
					height:140,
					title:"创建分支机构!",
					modal: true,
					Note:"ddddd",
					buttons: {
						"是": function() {
							var url ="${ctx}/project/sign/org/department!input.action?organizationId="+orgCode;
							var obj = new Object();
							mm = showDialogWindow(url);
							if(mm){
								if(mm.deptId){
									$("#branchOrgId").val(mm.deptId);
								}
								if(mm.depName){
									$("#deptName").val(mm.depName);
								}
							}
							$( this ).dialog( "close" );

						},
						"否": function() {
							var orgName = $("#orgName").val();
							var orgCode = $("#orgCode").val();
							$("#orgCode").val(orgCode);
							$("#deptName").val(orgName);
							$("#mark").val("0");
							$( this ).dialog( "close" );
						}
					}
			});
	 });
	 
	 
	 $("#inputForm").validate({
			rules:{
				deptName:{
					required:true
				},
   				contractOrder:{
   					required:true
   				},
	   			contractCost:{
	   	   			required:true,
					number:true
	   			}
			}
	});
});
function deletedesign(url){
	$.ajax({
		   type: "POST",
		   url: url,
		   success: function(msg){
			   if(msg=="1"){
				  alert("删除成功!");
				  window.returnValue=true;
				  window.close();
			   }else{
				  alert("删除失败!");
			   }
		   }
		});
}


function checkdraw(){
	var drawsign = $("input[name=drawIdList]:checked");
	var orgCode = $("#orgCode").val();
	if(!orgCode){
		alert("请选择单位!");
		return false;
	} else if (!drawsign.val()){
		alert("请选择图纸合同段或在分部分项中添加!");
	}else{
		return true;
	}
	return false;
}
function setValue(orgName , orgCode){
	$("#orgName").val(orgName);
	$("#orgCode").val(orgCode);
	$("#jquery-live-search").fadeOut();
	$("#deptName").focus();
}
function  addOrg(){
	$("#jquery-live-search").hide();
	var  url="${ctx}/project/org/designorg!input.action?typeId="+${contractKind};	
	 mm =showDialogWindow(url);
		if(mm){
			if(mm.orgName){
				$("#orgName").val(mm.orgName);
			}
			if(mm.orgId){
				$("#orgCode").val(mm.orgId);
			}
		}
}

</script>
<link href="${ctx}/styles/lightness/jquery-ui-1.8.12.custom.css"
	rel="stylesheet" />
</head>
<body>
<div id="caption">
<h6>设计合同段</h6>
</div>
<form action="${ctx}/project/sign/design!save.action" method="post" id="inputForm"
	class='yform'>
<fieldset><legend>合同段信息</legend>
<table width="200" class="noborder">
	<tr>
		<td>单位选择：</td>
		<td colspan="3"><c:if test="${empty id}">
			<input type="text" name="orgName" id="orgName" />
			<input type="hidden" name="orgCode" id="orgCode"  />
			</br>
			<div style="display: inline; color: orange">输入单位名称关键字，将自动补全;如果没有关联单位,显示【新增】</div>
		</c:if> <c:if test="${ not empty id }">
			<input type="text" name="orgName" id="orgName"
				value="${branchOrgCode.organization.orgName}" disabled="disabled" />
			<input type="hidden" name="orgCode" id="orgCode" value="${orgCode}" />
		</c:if> <input type="hidden" name="id" id="id" value="${id}" /></td>
	</tr>
	<tr>
		<td>创建分支机构：</td>
		<td colspan="3"><input id="deptName" name="deptName" type="text"
			value="${branchOrgCode.depName}" readonly="readonly"
			disabled="disabled" /> <input type="hidden" name="mark" id="mark" />
		<input type="hidden" id="branchOrgId" name="branchOrgId"
			value="${branchOrgCode.id}" /> <input type="hidden" name="projectId"
			value="${projectId}" /> <input type="hidden" name="contractKind"
			value="${contractKind}" /> </br>
		<c:if test="${empty id  }">
			<div style="display: inline; color:orange ">选择【是】,创建分支机构</div>
		</c:if>
		<div id="dialog-confirm" title="Empty the recycle bin?"
			style="display: none;">
		<p><span class="ui-icon ui-icon-alert"
			style="float: left; margin: 0 7px 20px 0;"></span>是否创建分支机构！</p>
		</div>
		</td>
	</tr>
	<tr>
		<td>合同段名称：</td>
		<td colspan="3"><input name="contractOrder" type="text"
			value="${contractOrder}" /></td>
	</tr>
	<tr>
		<td>起点桩号：</td>
		<td><input name="startPegNum" type="text" value="${startPegNum}" /></td>
		<td>终点桩号：</td>
		<td><input name="endPegNum" type="text" value="${endPegNum}" />
		</td>
	</tr>
	<tr>
		<td>开始时间：</td>
		<td><input id="beginDate" name="beginDate" type="text"
			value="<fmt:formatDate value="${beginDate}" pattern="yyyy-MM-dd"/>" />
		</td>
		<td>结束时间：</td>
		<td><input id="endDate" name="endDate" type="text"
			value="<fmt:formatDate value="${endDate}" pattern="yyyy-MM-dd"/>" />
		</td>
	</tr>
	<tr>
		<td>合同金额(万元)：</td>
		<td><input name="contractCost" type="text"
			value="${contractCost}" /></td>
		<td>合同编号：</td>
		<td><input name="contractNum" type="text" value="${contractNum}" /></td>
	</tr>
	<tr>
		<td>项目负责人：</td>
		<td><input name="principal" type="text"
			value="${principal}" /></td>
	</tr>
	<tr>
		<td>合同段主要内容：</td>
		<td colspan="3">
		<textarea rows="3" cols="60" name="contractContent">${contractContent}</textarea>
		</td>
	</tr>
	<tr>
		<td>备注：</td>
		<td colspan="3"><input name="remark" type="text"
			value="${remark}" /></td>
	</tr>
</table>
</fieldset>
<fieldset><legend>图纸标段</legend> <s:checkboxlist
	name="drawIdList" list="drawConList" listKey="id"
	listValue="contractOrder" theme="custom">
</s:checkboxlist></fieldset>
<div class="type-button"><input id="addSuper" type="submit"
	class="submit" value="保存" onclick="return checkdraw();" />&nbsp; <c:if
	test="${fn:length(id)!=0}">
	<input id="colseWin" type="button" value="删除" class="reset"
		onclick="deletedesign('${ctx}/project/sign/design!delete.action?id=${id}&projectId=${projectId}&contractKind=${contractKind}')" />
</c:if></div>
</form>
</body>
</html>
